_Pragma("once");

#include "VersionInfo.h"
#include "SingletonTemplate.h"
#include "ConfigInfo.h"
//#include "StatusInfo.h"
#include "ExtendDeviceConfig.h"
#include "NetEnvConfigInfo.h"
#include "Utility.h"

class cJSON;

class ConfigManager {
public:
    friend class SingletonTemplate<ConfigManager>;

    /** Default destructor */
    ~ConfigManager();

    VersionInfo& getVersionInfo() {
        return mversionInfo;
    }
    bool loadVersionInfo();
    bool saveVersionInfo();

    ConfigInfo& getConfigInfo() {
        return mconfigInfo;
    }
    bool loadConfigInfo();
    bool saveConfigInfo();

    ExtendDeviceConfig& getExtendDeviceConfig(){
        return mextendDeviceConfig;
    }

    bool loadExtendDeviceConfig();
    bool saveExtendDeviceConfig();

    bool parseExtendDeviceCondfig(cJSON* pRoot);

    const NetEnvConfigInfo& getNetEnvConfigInfo() {
        return mnetEnvConfigInfo;
    }

    bool loadNetEnvConfigInfo();
    bool saveNetEnvConfigInfo();


    void parseMap(cJSON* pRoot, Utility::StringMap& map);

    void saveMap(cJSON* pRoot, const Utility::StringMap& map);


protected:

    ConfigManager();

    bool stringifyAndSaveToFile(cJSON* pRoot, const std::string& pathfile);
    bool readAndParse(const std::string& pathfile, cJSON*& pRoot);

    VersionInfo mversionInfo;
    ConfigInfo mconfigInfo;

    ExtendDeviceConfig mextendDeviceConfig;

    NetEnvConfigInfo mnetEnvConfigInfo;
};


using ConfigManagerSingleton = SingletonTemplate<ConfigManager>;


